package com.spring.security.core.support;

import com.spring.security.core.properties.SecurityResponseCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;

/**
 * 返回实体
 *
 * @author seabed_moon
 */
@Slf4j
public class ServerResponseEntity {

    public static ServerResponse success(Object data, String msg) {
        ServerResponse serverResponse = new ServerResponse();
        serverResponse.setResponse_data(data);
        serverResponse.setResponse_code(HttpStatus.OK.value());
        serverResponse.setResponse_message(msg);
        return serverResponse;
    }


    public static ServerResponse fail(int code, String msg, Object data) {
        log.error(msg);
        ServerResponse serverResponse = new ServerResponse();
        serverResponse.setResponse_data(data);
        serverResponse.setResponse_code(code);
        serverResponse.setResponse_message(msg);
        return serverResponse;
    }

    public static ServerResponse fail(SecurityResponseCode securityResponseCode, Object data) {
        log.error(securityResponseCode.getMsg());
        ServerResponse serverResponse = new ServerResponse();
        serverResponse.setResponse_data(data);
        serverResponse.setResponse_code(securityResponseCode.getCode());
        serverResponse.setResponse_message(securityResponseCode.getMsg());
        return serverResponse;
    }
}
